package com.ecsolutions.controller;

import com.ecsolutions.entity.BaseEntity;
import com.ecsolutions.entity.OverviewEntity;
import com.ecsolutions.entity.asset.DepositCurrencyEntity;
import com.ecsolutions.entity.liability.LiabilityEntity;
import com.ecsolutions.service.asset.DepositService;
import com.ecsolutions.service.liability.LiabilityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by Administrator on 2017/5/15.
 */
@RestController
@RequestMapping("/overview")
public class OverviewController {
    @Autowired
    private DepositService depositService;
    @Autowired
    private LiabilityService liabilityService;

    public DepositService getDepositService() {
        return depositService;
    }

    public LiabilityService getLiabilityService() {
        return liabilityService;
    }

    @CrossOrigin(origins = "*")
    @GetMapping("/{customer_code}")
    public BaseEntity getOverview(@PathVariable("customer_code") String customer_code) {
        BaseEntity ret = new BaseEntity();
        try {
            OverviewEntity overviewEntity = new OverviewEntity();
            List<DepositCurrencyEntity> depositEntities = depositService.getAssetList(customer_code);
            List<LiabilityEntity> liabilityEntities = liabilityService.getLiabilityList(customer_code);
            overviewEntity.setAssets(depositEntities);
            overviewEntity.setLiabilities(liabilityEntities);
            ret.setData(overviewEntity);
        } catch (Exception ex) {
            ret.setCode(-1);
            ret.setMsg("get overview failed!");
        }
        ret.setCode(200);
        ret.setMsg("success");
        return ret;
    }
}
